module.exports = {
	prefix: "/user/MA",
	get: {
		"/ach/list/by_bus_id/:bus_id": function() {
			var user = role.getUser(this);
			var query = this.request.query;
			this.body = ResponObj("json", user.getMAAchListByBusId(this.params.bus_id, query));
		},
		"/shop/list": function() {
			var user = role.getUser(this);
			this.body = ResponObj("json", user.getAllShopList());
		},
		"/shop/list/by_bus_id/:bus_id": function() {
			var user = role.getUser(this);
			this.body = ResponObj("json", user.getShopListByBusId(this.params.bus_id));
		},
		"/shop/detail/by_id/:shop_id": function() {
			var user = role.getUser(this);
			var shop_id = this.params.shop_id;
			this.body = ResponObj("json", user.getShopById(shop_id))
		}
	},
	post: {
		//申请店铺
		"/shop/apply_shop/:bus_id": function() {
			var user = role.getUser(this);
			var MA = user.getMAByBusId(this.params.bus_id);
			this.body = ResponObj("json", MA.applyAddShop(this.request.body));
		}
	},
	put: {
		"/update_MA/:MA_id": function() {
			var bus = role.getBus(this);
			var MA_id = this.params.MA_id;
			var body = this.request.body;
			bus.updateMA(MA_id, body);

			if (body.return_type === "MA_list") {
				this.body = ResponObj("json", bus.getMADetailList());
			} else {
				this.body = ResponObj("json", bus.getMADetail(MA_id));
			}
		}
	},
	"delete": {
		"/remove_MA/:MA_id": function() {
			var bus = role.getBus(this);
			var MA_id = this.params.MA_id;
			var body = this.request.body;
			bus.removeMA(MA_id);
			this.body = ResponObj("json", bus.getMADetailList());
		}
	}
}
var role = require("./role");
var BusCon = require("../../core/bus/_con");
var UserCon = require("../../core/user/_con");
var GoodsCon = require("../../core/goods/_con");
var AchCon = require("../../core/ach/_con");
var db = require("../../core/db/index");
var config = require("../../core/_include/config");
var ResponObj = require("../_include/responObj");